<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <button id="btn">按钮</button>
    <script type="text/javascript">
        //什么是防抖
        /* 
           函数防抖 ：防抖表示当指定时间内持续触发某个事件时，该事件会进行初始刷新，重新开始计算。
        */


        function debounce(fn, delay) {
            var timer = null;
            return function () {
                //清除上一次的延时器
                clearTimeout(timer);
                //重新设置新的延时器
                timer = setTimeout(() => {
                    fn.apply(this);
                }, delay);
            }
        }


        document.getElementById('btn').onclick = debounce(() => {
            console.log('点击数件被触发了' + Date.now());
        }, 1000)
    </script>


</body>

</html>